﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.Unity;
using System.Configuration;
using Microsoft.Practices.Unity.Configuration;

namespace Skynet.BusinessLogic.Test
{
    public class UnityHelper
    {
        public static IUnityContainer BuildUnityContainer() 
        {
            var Container = Infrastructure.Aspect.Patterns.Singleton<UnityContainer, IUnityContainer>.Instance;

            var fileMapPolicies = new ExeConfigurationFileMap { ExeConfigFilename = @"C:\Skynet\Skynet.BusinessLogic.Test\Config\Aspect.config" };
            var configurationPolicies = ConfigurationManager.OpenMappedExeConfiguration(fileMapPolicies, ConfigurationUserLevel.None);
            var unitySectionPolicies = (UnityConfigurationSection)configurationPolicies.GetSection("unity");            
            Container.LoadConfiguration(unitySectionPolicies);

            var fileMapDataAccess = new ExeConfigurationFileMap { ExeConfigFilename = @"C:\Skynet\Skynet.BusinessLogic.Test\Config\DataAccess.config" };
            var configurationDataAccess = ConfigurationManager.OpenMappedExeConfiguration(fileMapDataAccess, ConfigurationUserLevel.None);
            var unitySectionDataAccess = (UnityConfigurationSection)configurationDataAccess.GetSection("unity");
            Container.LoadConfiguration(unitySectionDataAccess);


            return Container; 

        }
    }
}
